package com.health.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.health.common.Result;
import com.health.entity.Hospital;
import com.health.entity.pojo.PageData;
import com.health.entity.pojo.dto.QueryHospitalDTO;
import com.health.entity.pojo.vo.HospitalVO;
import com.health.mapper.HospitalMapper;
import com.health.service.IHospitalService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 医院表 服务实现类
 * </p>
 *
 * @author sanchuan
 * @since 2023-04-16
 */
@Service
public class HospitalServiceImpl extends ServiceImpl<HospitalMapper, Hospital> implements IHospitalService {

    @Autowired
    private HospitalMapper hospitalMapper;
    private LambdaQueryWrapper<Hospital> wrapper;

    /**
     * 获取分页数据+条件查询
     * @param pageNum
     * @param pageSize
     * @param queryHospitalDTO
     * @return
     */
    @Override
    public PageData listHospitalPage(Integer pageNum, Integer pageSize, QueryHospitalDTO queryHospitalDTO) {
        IPage<Hospital> page = new Page<>(pageNum,pageSize);
        //分页条件 医院类型、等级、名称
        wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(queryHospitalDTO.getType() != null,Hospital :: getType,queryHospitalDTO.getType())
                .eq(queryHospitalDTO.getLevel() != null,Hospital :: getLevel,queryHospitalDTO.getLevel())
                .like(queryHospitalDTO.getName() != null,Hospital :: getName,queryHospitalDTO.getName());

        IPage<Hospital> iPage = hospitalMapper.selectPage(page,wrapper);
        return new PageData(iPage.getTotal(),iPage.getRecords());
    }

    /**
     * 修改医院上架状态
     * @return
     */
    @Override
    public Boolean changeHospitalShelves(boolean isShelves, Integer id) {
        return hospitalMapper.changeHospitalShelves(isShelves,id);
    }

    /**
     * 批量上/下架医院
     * @param isShelves
     * @param ids
     * @return
     */
    @Override
    public Boolean changeHospitalShelvesMulti(boolean isShelves, List<Integer> ids) {
        return hospitalMapper.changeHospitalShelvesMulti(isShelves,ids);
    }

    /**
     * 批量删除医院
     * @param ids
     * @return
     */
    @Override
    public Boolean deleteHospitalShelvesMulti(List<Integer> ids) {
        return hospitalMapper.deleteHospitalShelvesMulti(ids);
    }

    /**
     * 获得医院列表
     * @return
     */
    @Override
    public List<HospitalVO> getHospitals() {
        return hospitalMapper.getHospitals();
    }
}
